import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86186
 * Date: 2023-11-20
 * Time: 10:05
 */
@WebServlet("/index")
public class IndexServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession httpSession = req.getSession(false);
        resp.setContentType("text/html; charset=utf8");
        if (httpSession == null) {
            resp.getWriter().write("对不起，您当前未登录");
            return;
        }
        String username = (String)httpSession.getAttribute("username");
        Long loginTime = (Long)httpSession.getAttribute("loginTime");
        String responBody = "欢迎你" + username + "上次登录时间为" + loginTime;
        resp.getWriter().write(responBody);
    }
}
